package com.wbl.tijianssm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wbl.tijianssm.mapper.CheckitemMapper;
import com.wbl.tijianssm.mapper.CheckitemdetailedMapper;
import com.wbl.tijianssm.mapper.SetmealMapper;
import com.wbl.tijianssm.pojo.Checkitem;
import com.wbl.tijianssm.pojo.Checkitemdetailed;
import com.wbl.tijianssm.pojo.Orders;
import com.wbl.tijianssm.pojo.Users;
import com.wbl.tijianssm.response.ApiRestResponse;
import com.wbl.tijianssm.response.TijianExceptionEnum;
import com.wbl.tijianssm.service.OrdersService;
import com.wbl.tijianssm.mapper.OrdersMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author yy
* @description 针对表【orders】的数据库操作Service实现
* @createDate 2024-09-18 10:09:07
*/
@Service
public class OrdersServiceImpl extends ServiceImpl<OrdersMapper, Orders>
    implements OrdersService{

    @Autowired
    OrdersMapper ordersMapper;


    @Autowired
    SetmealMapper setmealMapper;

    @Autowired
    CheckitemdetailedMapper checkitemdetailedMapper;


    @Override
    public ApiRestResponse ConfirmOrder(Orders order) {
        int i = ordersMapper.insertOrder(order);

        if(i>0){
            return ApiRestResponse.success(order);
        }else {
            return ApiRestResponse.error(TijianExceptionEnum.SYSTEM_ERROR);
        }
    }

    @Override
    public ApiRestResponse getOrderlist(Orders order) {
        List<Orders> orders = ordersMapper.getOrderForSetmeal(order.getUserid());
        System.out.println(order);
        return ApiRestResponse.success(orders);
    }

    @Override
    public ApiRestResponse editOrder(Orders order) {
        System.out.println(order);
        int i = ordersMapper.updateOrderState(order.getOrderid(),order.getState());
        if (i>0) return ApiRestResponse.success(order);
        else return ApiRestResponse.error(TijianExceptionEnum.SYSTEM_ERROR);
    }

//    @Override
//    public ApiRestResponse getOrderById(Orders order) {
//        Orders orders = ordersMapper.selectByid(order.getOrderid());
//        orders.setSetmeal(setmealMapper.selectdetailById(orders.getSmid()));
//        for (Checkitem checkitem :orders.getSetmeal().getCheckitems() ){
//            QueryWrapper<Checkitemdetailed> queryWrapper = new QueryWrapper<>();
//            queryWrapper.eq("ciId",checkitem.getCiid());
//            checkitem.setCheckitemdetaileds(checkitemdetailedMapper.selectList(queryWrapper));
//        }
//        return ApiRestResponse.success(orders);
//    }


}




